//
//  PokemonInfoRow.swift
//  ToDo
//
//  Created by yanhangpu on 2021/7/9.
//

import SwiftUI

struct ToolButtonModifier: ViewModifier {
    func body(content: Content) -> some View {
            content
                .font(.system(size: 25))
                .foregroundColor(.white)
                .frame(width: 30, height: 30)
    }
}

struct LeadingModifier: ViewModifier {
    func body(content: Content) -> some View {
            content
                .padding(EdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 0))
    }
}

struct TrailingModifier: ViewModifier {
    func body(content: Content) -> some View {
            content
                .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 20))
    }
}

struct PokemonInfoRow: View {
    
    var item: PokeMasterItem
        
    var body: some View {
        let expanded:Bool = item.expanded == 1
        let height:CGFloat = expanded ? 120 : 80
        VStack {
            PokeInfoView(item: item)
            if expanded {
                PokeStarView(item: item) { actionType in
                    print(actionType,item)
                }
            }
        }
        .frame(width: UIScreen.main.bounds.size.width-40, height: height, alignment: .center)
        .background(
            ZStack {
                RoundedRectangle(cornerRadius: 20)
                    .stroke(Color.blue, style: StrokeStyle(lineWidth: 4))
                RoundedRectangle(cornerRadius: 20)
                    .fill(
                        LinearGradient(
                            gradient: Gradient(colors: [Color.white, Color.green]),
                            startPoint: .leading,
                            endPoint: .trailing
                        )
                    )
            }
        ).padding([.leading, .trailing, .top])
    }
}

struct PokemonInfoRow_Previews: PreviewProvider {
    static var previews: some View {
        let pokeMasterData: [PokeMasterItem] = PokeMasterModel.loadPokeMasterData()
        PokemonInfoRow(item: pokeMasterData[0])
    }
}
